#include "include.h"
using namespace std;
// left obj, right obj
// returns true if there is any collision, false if there is no collision.
bool Collision::checkCollision(DrawableObj &left, DrawableObj &right)
{
    // obj 1 boundries
    int oneLeft = left.getXPosition();
    int oneRight = left.getXPosition() + left.getXResolution();
    int oneTop = left.getYPosition();
    int oneBottom = left.getYPosition() + left.getYResolution();
    // obj 2 boundries
    int twoLeft = right.getXPosition();
    int twoRight = right.getXPosition() + right.getXResolution();
    int twoTop = right.getYPosition();
    int twoBottom = right.getYPosition() + right.getYResolution();

    // left-right collisions
    if(oneRight > twoLeft && twoRight > oneLeft &&
        oneBottom > twoTop && twoBottom > oneTop) return true;
    return false;
}
// boundry collisions
// obj, background
bool Collision::checkBoundryCollision(DrawableObj &left, DrawableObj &back)
{
    // obj 1 boundries
    int oneLeft = left.getXPosition();
    int oneRight = left.getXPosition() + left.getXResolution();
    int oneTop = left.getYPosition();
    int oneBottom = left.getYPosition() + left.getYResolution();
    // background obj boundries
    int windowLeft = back.getXPosition();
    int windowRight = back.getXPosition() + SCREEN_W;
    int windowTop = back.getYPosition();
    int windowBottom = back.getYPosition() + SCREEN_H;
    // window border collisions
    if(oneLeft < windowLeft || oneRight > windowRight || oneTop < windowTop || oneBottom > windowBottom) return true;

    return false;
}
bool Collision::checkCollision(DrawableObj &left, DrawableObj &right, int distanceOffset)
{
    // obj 1 boundries
    int oneRight = left.getXPosition() + left.getXResolution();
    // obj 2 boundries
    int twoLeft = right.getXPosition();

    // left-right collisions
    if((oneRight + distanceOffset) > twoLeft)
        return true;

    return false;
}
bool Collision::checkBoundryCollision(DrawableObj &left, DrawableObj &back, int distanceOffset)
{
    // obj 1 boundries
    int oneLeft = left.getXPosition();
    int oneRight = left.getXPosition() + left.getXResolution();

    // background obj boundries
    int windowLeft = back.getXPosition();
    int windowRight = back.getXPosition() + SCREEN_W;
    // window border collisions
    if(oneLeft < (windowLeft + distanceOffset) || (oneRight + distanceOffset) > windowRight) return true;

    return false;
}
void Collision::printMe(DrawableObj &left, DrawableObj &right, DrawableObj &back)
{
    // obj 1 boundries
    int oneLeft = left.getXPosition();
    int oneRight = left.getXPosition() + left.getXResolution();
    int oneTop = left.getYPosition();
    int oneBottom = left.getYPosition() + left.getYResolution();
    // obj 2 boundries
    int twoLeft = right.getXPosition();
    int twoRight = right.getXPosition() + right.getXResolution();
    int twoTop = right.getYPosition();
    int twoBottom = right.getYPosition() + right.getYResolution();
    // background obj boundries
    int windowLeft = back.getXPosition();
    int windowRight = back.getXPosition() + SCREEN_W;
    int windowTop = back.getYPosition();
    int windowBottom = back.getYPosition() + SCREEN_H;

    cout << "oneLeft : " << oneLeft << endl;
    cout << "oneRight : " << oneRight << endl;
    cout << "oneTop : " << oneTop << endl;
    cout << "oneBottom : " << oneBottom << endl;
    cout << "twoLeft : " << twoLeft << endl;
    cout << "twoRight : " << twoRight << endl;
    cout << "twoTop : " << twoTop << endl;
    cout << "twoBottom : " << twoBottom << endl;
    cout << "windowLeft : " << windowLeft << endl;
    cout << "windowRight : " << windowRight << endl;
    cout << "windowTop : " << windowTop << endl;
    cout << "windowBottom : " << windowBottom << endl;
}
